package com.keke.myblogv1.girlfriend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keke.myblogv1.girlfriend.dto.QueryMyBlogGirlfriendByPageDTO;
import com.keke.myblogv1.girlfriend.entity.MyBlogGirlfriend;
import com.keke.myblogv1.girlfriend.mapper.MyBlogGirlfriendMapper;
import com.keke.myblogv1.girlfriend.service.MyBlogGirlfriendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author Derrick
 * @since 2022-07-31
 */
@Service
public class MyBlogGirlfriendServiceImpl extends ServiceImpl<MyBlogGirlfriendMapper, MyBlogGirlfriend> implements MyBlogGirlfriendService {

    @Resource
    private MyBlogGirlfriendMapper myBlogGirlfriendMapper;

    @Override
    public List<MyBlogGirlfriend> getGirlfriendList() {
        LambdaQueryWrapper<MyBlogGirlfriend> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MyBlogGirlfriend::getStatus,"1");
        List<MyBlogGirlfriend> myBlogGirlfriends = myBlogGirlfriendMapper.selectList(queryWrapper);
        return myBlogGirlfriends;
    }

    @Override
    public Page<MyBlogGirlfriend> getGirlfriendListByPage(QueryMyBlogGirlfriendByPageDTO queryMyBlogGirlfriendByPageDTO) {
        Page<MyBlogGirlfriend> page = new Page<>(queryMyBlogGirlfriendByPageDTO.getPageNum(), queryMyBlogGirlfriendByPageDTO.getPageSize());
        LambdaQueryWrapper<MyBlogGirlfriend> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MyBlogGirlfriend::getStatus,"1");
        queryWrapper.orderByDesc(MyBlogGirlfriend::getCreateDate);
        Page<MyBlogGirlfriend> myBlogGirlfriendPage = myBlogGirlfriendMapper.selectPage(page, queryWrapper);
        return myBlogGirlfriendPage;
    }

    @Override
    public boolean insertGirlfriend(MyBlogGirlfriend myBlogGirlfriend) {
        myBlogGirlfriend.setCreateBy("admin");
        myBlogGirlfriend.setCreateDate(new Date());
        int insert = myBlogGirlfriendMapper.insert(myBlogGirlfriend);
        if(insert>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean updateGirlfriend(MyBlogGirlfriend myBlogGirlfriend) {
        myBlogGirlfriend.setUpdateBy("admin");
        myBlogGirlfriend.setUpdateDate(new Date());
        int i = myBlogGirlfriendMapper.updateById(myBlogGirlfriend);
        if(i>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean deleteGirlfriend(MyBlogGirlfriend myBlogGirlfriend) {
        myBlogGirlfriend.setStatus("0");
        myBlogGirlfriend.setUpdateBy("admin");
        myBlogGirlfriend.setUpdateDate(new Date());
        int i = myBlogGirlfriendMapper.updateById(myBlogGirlfriend);
        if(i>0){
            return true;
        }else{
            return false;
        }
    }
}
